﻿//WorkingTime.cs
//Copyright (c) 2013 StockSharp LLC, all rights reserved.
//This code module is part of StockSharp library.
//This code is licensed under the GNU GENERAL PUBLIC LICENSE Version 3.
//See the file License.txt for the license details.
//More info on: http://stocksharp.com

namespace StockSharp.BusinessEntities
{
	using System;
	using System.Linq;
	using System.Runtime.Serialization;

	using Ecng.Common;
	using Ecng.ComponentModel;

	/// <summary>
	/// Класс, описывающий режим работы (время, выходные дни и т.д.).
	/// </summary>
	public class WorkingTime : Cloneable<WorkingTime>
	{
		/// <summary>
		/// Создать <see cref="WorkingTime"/>.
		/// </summary>
		public WorkingTime()
		{
		}

		private Range<TimeSpan>[] _times = new Range<TimeSpan>[0];

		/// <summary>
		/// Время работы биржи. Например, для RTS значения равны 10:00-14:00, 14:03-18:45 и 19:00-23:50.
		/// </summary>
		[DataMember]
		public Range<TimeSpan>[] Times
		{
			get { return _times; }
			set
			{
				if (value == null)
					throw new ArgumentNullException("value");

				_times = value;
			}
		}

		private DateTime[] _specialWorkingDays = new DateTime[0];

		/// <summary>
		/// Рабочие дни, выпадающие на субботу и воскресенье.
		/// </summary>
		public DateTime[] SpecialWorkingDays
		{
			get { return _specialWorkingDays; }
			set
			{
				if (value == null)
					throw new ArgumentNullException("value");

				_specialWorkingDays = value;
			}
		}

		private DateTime[] _specialHolidays = new DateTime[0];

		/// <summary>
		/// Выходные дни, выпадающие на будни.
		/// </summary>
		public DateTime[] SpecialHolidays
		{
			get { return _specialHolidays; }
			set
			{
				if (value == null)
					throw new ArgumentNullException("value");

				_specialHolidays = value;
			}
		}

		/// <summary>
		/// Создать копию объекта <see cref="WorkingTime"/>.
		/// </summary>
		/// <returns>Копия объекта.</returns>
		public override WorkingTime Clone()
		{
			return new WorkingTime
			{
				Times = Times.Select(t => t.Clone()).ToArray(),
				SpecialWorkingDays = SpecialWorkingDays.ToArray(),
				SpecialHolidays = SpecialHolidays.ToArray()
			};
		}
	}
}